
function goods_file_queued_handler(file) {
	var id = 'one_' + file.index;
	var one = '<li id="' + id + '"><div class="upload_process">等待上传</div></li>'
	$('#picture_box').append(one);
}

function goods_file_queue_error_handler(file, code, msg) {

}

function goods_file_dialog_complete_handler(selected, queued) {
	if (this.getStats().files_queued > 0) {
		this.startUpload();
	}
}

function goods_upload_start_handler(file) {

}

function goods_upload_progress_handler(file, complete, total) {
	var id = 'one_' + file.index;
	$('#' + id).find('.upload_process').html(((complete / total) * 100).toFixed(2) + '%');
}

function goods_upload_success_handler(file, data, response) {
	var id = 'one_' + file.index;
	var $li = $('#' + id);

	data = eval('(' + data + ')');

	$li.empty().append('<div style="display:none;"><input type="hidden" name="urls[]" value="'+data.msg+'" /><img src="'+data.msg+'" width="160" height="160" /><i class="main icon-ok" title="设为主图"></i><i class="delete icon-remove" title="删除"></div>').children().fadeIn();
}

function goods_upload_error_handler(file, code, message) {
	var id = 'one_' + file.index;
	$('#' + id).find('.upload_process').html('上传失败');
}

function goods_upload_complete_handler(file) {
	if (this.getStats().files_queued == 0) {
		$('#picture_box').sortable('destroy');
		$('#picture_box').sortable({
			revert: true,
			cursor: 'move',
			opacity: 0.5
		});
	}
}


//显示图片
function show_img(img, order)
{
	order = order == undefined ? 100 : order;
	$("#picture_box").append('<li><div><input type="hidden" name="urls[]" value="'+img+'" /><img src="'+img+'" width="160" height="160" /><i class="main icon-ok" title="设为主图"></i><i class="delete icon-remove" title="删除"></i></div></li>');
}

$(function(){
	
	//添加规格
	$("#add_sku").click(function(){
		art.dialog({
			"id" : "add_sku_dialog",
			"title" : "增加规格",
			"content" : "哈哈",
			"button" : [
				{
					"value" : "确定",
					"callback" : function(){
						
					}
				},
				{
					"value" : "取消",
				}
			]
		});
	});
	
	//添加相关产品
	$("#add_related").click(function(){
		art.dialog({
			"id" : "add_related_dialog",
			"title" : "商品搜索",
			"content" : '<div style="width:700px;height:400px;"><div><select id="search_type" class="select"><option value="1">货号</option><option value="2">商品名称</option><option value="3">商品ID</option><option value="4">商品标题</option></select><input type="text" id="search_word" value="" class="w300 input" style="margin-left:20px;" /><input type="button" id="search_submit" value="搜索" class="button" style="margin-left:20px;" /></div><div style="padding-top:10px;"><select id="search_category" class="select"><option value="0">请选择</option></select> 分类 <select id="search_brand" class="select"><option value="0">请选择</option></select> 品牌 <select id="search_suppliers" class="select"><option value="0">请选择</option></select> 供应商</div><div id="search_list"><ul><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li><li>aaaaaaaaaa</li></ul></div><div id="search_page"></div></div>',
			"button" : [
				{
					"value" : "确定",
					"callback" : function(){
						
					}
				},
				{
					"value" : "取消",
				}
			]
		});
	});
	
	$("#picture_box li").live('mouseover', function(){
		$(this).find('img').css('border-color', 'green');
		$(this).find('i').show();
	});
	$("#picture_box li").live('mouseout', function(){
		$(this).find('img').css('border-color', '#ccc');
		$(this).find('i').hide();
	});

	$("#picture_box li .main").live('click', function(){
		var img = $(this).parent().find('img').attr('src');
		$(':input[name="pic"]').val(img);
		if ($('#upload_pic').nextAll('img').size() > 0) {
			$('#upload_pic').nextAll('img').first().attr('src', img);
		} else {
			$('#upload_pic').after('<br /><img src="' + img + '" width="100" height="100" />');
		}
		alert('ok');
	});

	$("#picture_box li .delete").live('click', function(){
		$(this).parent().parent().remove();
	});
	
});